<?php
namespace Admin\Controller;
use Think\Controller;
class ConfController extends Controller {
    public function lst(){
    	$conf = D('conf');
    	$count      = $conf->count();// 查询满足要求的总记录数
    	$Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    	$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
    	$list = $conf->order('cf_id asc')->limit($Page->firstRow.','.$Page->listRows)->select();
    	$this->assign('list',$list);// 赋值数据集$this->assign('page',$show);// 赋值分页输出
    	$this->assign('page',$show);// 赋值分页输出
        $this->display();
    }

	public function add(){
		$conf = D('conf');
		if (IS_POST) {
			$data['cf_name']=I('cf_name');
			$data['cf_ename']=I('cf_ename');
			$data['cf_type']=I('cf_type');
			$data['cf_values']=I('cf_values');
			$data['cf_value']=I('cf_value');
			if ($conf->create($data)) {
				if ($conf->add()) {
					$this->success('添加成功！',U('lst'));
				}else{
					$this->error('添加失败！');
				}
			}else{
				$this->error($conf->getError());
			}
			return;
		}
        $this->display();
    }


	public function edit($cf_id){
		$conf = D('conf');
		$confs = $conf->find($cf_id);
		$this->assign('confs',$confs);
		if (IS_POST) {
			$data['cf_id']=I('cf_id');
			$data['cf_name']=I('cf_name');
			$data['cf_ename']=I('cf_ename');
			$data['cf_type']=I('cf_type');
			$data['cf_values']=I('cf_values');
			$data['cf_value']=I('cf_value');
			if ($conf->create($data)) {
				if ($conf->save()) {
					$this->success('修改成功！',U('lst'));
				}else{
					$this->error('修改失败！');
				}
			}else{
				$this->error($conf->getError());
			}
			return;
		}        
        $this->display();
    }

	public function del($cf_id){
		$conf = D('conf');
		if ($conf->delete($cf_id)) {
			$this->success('删除成功！',U('lst'));
		}else{
			$this->error('删除失败！',U('lst'));
		}
		$this->display();
	}

	public function bdel(){
		$conf = D('conf');
		$bdel = I('post.bdel');
		$bdelid = implode(',',$bdel);
		if ($bdelid) {
			if ($conf->delete($bdelid)) {
				$this->success('批量删除成功！',U('lst'));
			}else{
				$this->error('批量删除失败！',U('lst'));
			}
		}

	}

	 public function conflst(){
		$conf = D('conf');
		if (IS_POST) {
			$ret = array();
			$ret = $_POST;//接收到的所有数据
			if($conf->xiugai($ret)!==false){
				$this->success('修改成功！',U('conflst'));
			}else{
				$this->error('修改失败！',U('conflst'))
			}
			return;
		}
		$confs = $conf->select();
		$this->assign('confs',$confs);
	 	$this->display();
	 }
   
}